
$(function(){

    //RENDER***********************************************************
    app.ajax('get',app.url('getIndexData.php'),{},function(data){
        var obj = data;
        //banner数据
        $("[data-name='bannerPath']").prop('src',app.imgUrl(obj.bannerPath));
        //计数数据
        var countObj = $('#count');
        for(var i in obj.count){
            countObj.find("[data-name='"+i+"']").text(obj.count[i])
        }

        //相册数据
        var listObj = $('.item-box');
        //listObj.css('height',listObj.css('width'));
        for(var j=0;j<obj.imgArrPath.length;j++){
            if(j==0){
                $('#latest').find("[data-name='time']").text(obj.imgArrPath[j].time);
            }
            listObj.eq(j).css('background-image','url('+app.imgUrl('photo/'+obj.imgArrPath[j].imgPath)+')').attr('data-id',obj.imgArrPath[j].id);
        }

        //说说数据sign-text
        var liTextObj = $('#main-sign');
        liTextObj.find("[data-name='text']").text(obj.sayObj.text);
        liTextObj.find("[data-name='time']").text(obj.sayObj.time);
        //文章数据
        var artObj = $('#main-article');
        //artObj.find("[data-name='imgPath']").prop('src','img/'+obj.articleObj.imgPath);
        artObj.find(".checked").attr('data-id',obj.articleObj.id);
        artObj.find("[data-name='imgPath']").css('background-image','url('+app.imgUrl('art/'+obj.articleObj.imgPath)+')');
        artObj.find("[data-name='title']").text(obj.articleObj.title);
        artObj.find("[data-name='text']").text(obj.articleObj.text);  artObj.find("[data-name='text']").text(obj.articleObj.text);
    });

    //OVER**********************************************************************
    //文章查看
    $('.checked').on('tap',function(){
        open('article_detail.html?'+$(this).attr('data-id'),'_self');
    });

    //下载
    $('.down').on('tap',function(){
        $.alert('将要下载app?',function(){
            window.location = 'http://www.featsky.com/m-featsky/app/featsky.apk';
        })
    });
    //==========================================================
    //调用组件
    var imgObj = null;
    imgObj = new Album({
        currentObj:$('.album'),
        speed:400,
        //回退按钮回调函数
        callback:null,
        scale:false
    });

    $('.latest-item').on('tap','.item-box',function(){
        var _this = this,imgId = '',imgArr = [],str = '';
        //渲染组件
        var pageImgObj = $('.latest-item').find('.item-box');
        pageImgObj.each(function(index,obj){
            if(obj == _this){imgId = index}
            var imgPath = obj.style.backgroundImage;
            imgPath = imgPath.match(/(http.+\.(jpg|png))/)[1];
            imgArr.push(imgPath);
        });
        var imgModel = $('#model-2').clone();
        $(imgArr).each(function(index,obj){
            imgModel.find('img').attr('src',obj);
            str += imgModel.html()
        });
        $(".album-item").html(str);

        imgObj.init(imgId,imgArr.length);
    });

})